<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

include dirname(__FILE__) . '/../../class/_core.php';

$userid = intval($_COOKIE['userid']);
$old = strtolower(hash('sha256', $_POST['_old']));
$new = strtolower(hash('sha256', $_POST['_new']));

if ($userid > 0) {
    $res1 = Db::get_instance()->query("SELECT * FROM `fac_users` WHERE user_id = $userid AND user_password = '$old';");
    if(is_array($res1[0])){
        $rt = Db::get_instance()->query("UPDATE `fac_users` SET user_password = '$new' WHERE user_id = $userid AND user_password = '$old';");
        echo $rt ? 1 : 0;
    } else {
        echo 0;
    }
} else {
    echo 0;
}